Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2GameUser = require("GameUser");
var $2ServerConfig = require("ServerConfig");
var $2EventCenter = require("EventCenter");
var $2EventDefine = require("EventDefine");
var $2Platformconf = require("Platformconf");
var $2MiniBase = require("MiniBase");
exports.default = /* */function (_l$default2) {
  function _class29() {
    var _this160;
    babel_classCallCheck(this, _class29);
    _this160 = _callSuper(this, _class29);
    _this160.loginDay = -1;
    _this160.countLevel = 3;
    _this160.systemInfo = null;
    _this160.version = "";
    _this160.versionList = [];
    _this160.adVersionList = [10, 3, 66];
    _this160.isRewardedAd = false;
    _this160.playADCallBack = null;
    _this160.interstitialAd = null;
    _this160.bannerAd = null;
    _this160.isShow = false;
    _this160.active = !!window.my;
    console.log("支付宝小游戏");
    var e = cc.sys.localStorage.getItem("zfbDay");
    null == e && "null" == e && "" == e || (_this160.loginDay = e);
    var t = new Date().getDate();
    console.log(new Date().toString());
    console.log("loginDay", _this160.loginDay);
    console.log("day：", t);
    if (t != _this160.loginDay) {
      _this160.countLevel = 0;
      console.log("刷新countLevel");
    }
    return _this160;
  }
  babel_inherits(_class29, _l$default2);
  return babel_createClass(_class29, [{
    key: "init",
    value: function init(e) {
      if (window.my && window.my.eqapi) {
        var _e88 = $2Platformconf.default.eqconfig();
        _e88.onLoginned = function (e) {
          console.log("++++res.id:,", e.id);
          console.log("++++uid:,", e.uid);
          console.log("++++-------------------");
          if ("" == $2GameUser.default.getInstance().openid) {
            $2GameUser.default.getInstance().openid = e.uid;
            $2GameUser.default.getInstance().id = e.id;
          }
        };
        window.my.eqapi.init(_e88);
        console.log("=======================config:", JSON.stringify(_e88));
      }
      try {
        window.my.setKeepScreenOn({
          keepScreenOn: true,
          success() {
            console.log("常亮开启");
          }
        });
      } catch (t) {}
      if (window.my) {
        var _e89 = window.my.getLaunchOptionsSync();
        $2EventCenter.default.postWaitEvent($2EventDefine.default.EVENT_ONSHOW, _e89);
        window.my.onShow(function (e) {
          console.log("onShow", e.query);
          $2EventCenter.default.postWaitEvent($2EventDefine.default.EVENT_ONSHOW, e);
        });
        window.my.onHide(function (e) {
          $2EventCenter.default.postWaitEvent($2EventDefine.default.EVENT_ONHIDE, e);
        });
        this.eqInit();
        this.getSystemInfo(null);
      }
    }
  }, {
    key: "eqInit",
    value: function eqInit() {
      window.my.eqRegisterHandler && window.my.eqRegisterHandler(function (e) {
        console.log("++++++++++++++", e);
        $2ServerConfig.default.getInstance().init(e);
      });
    }
  }, {
    key: "getSystemInfo",
    value: function getSystemInfo(e) {
      var _this161 = this;
      if (this.systemInfo) {
        e && e(this.systemInfo);
      } else {
        window.my.getSystemInfo({
          success(t) {
            console.log("getSystemInfo success:" + t);
            if (t && t.version) {
              _this161.systemInfo = t;
              _this161.version = t.version;
              console.log("支付宝版本:", t.version);
              console.log("窗口宽:", t.windowWidth);
              console.log("窗口高:", t.windowHeight);
              console.log("屏幕宽:", t.screenWidth);
              console.log("屏幕高:", t.screenHeight);
              var _e90 = t.version.split(".");
              for (var _t78 = 0; _t78 < _e90.length; _t78++) {
                _this161.versionList[_t78] = parseInt(_e90[_t78]);
              }
            }
            e && e(t);
          },
          fail(e) {
            console.log("getSystemInfo  fail" + e);
          },
          complete() {
            console.log("getSystemInfo complete");
          }
        });
      }
    }
  }, {
    key: "play_AD",
    value: function play_AD(e, t) {
      var _this162 = this;
      this.playADCallBack = e;
      if (this.isAdOk()) {
        this.isRewardedAd = true;
        if (this.rewardedAd) {
          this.rewardedAd.show().catch(function () {
            _this162.rewardedAd.load().then(function () {
              console.log("激励广告加载成功3");
              _this162.rewardedAd.show();
            });
          });
        } else {
          var _e91 = $2Platformconf.default.Instance.getconfig().ZFBGame.video[0];
          console.log("激励广告Id:", _e91);
          this.rewardedAd = window.my.createRewardedAd({
            adUnitId: _e91
          });
          this.rewardedAd.onLoad(function () {
            console.log("激励广告加载成功1");
            _this162.isRewardedAd && _this162.rewardedAd.show();
          });
          this.rewardedAd.onError(function (e) {
            console.log("激励广告加载失败:", e);
          });
          this.rewardedAd.onClose(function (e) {
            _this162.isRewardedAd = false;
            console.log("rewardedAd.onClose:", +e);
            if (e && e.isEnded) {
              console.log("正常播放结束，可以下发游戏奖励");
              _this162.playADCallBack && _this162.playADCallBack(true);
            } else {
              console.log("播放中途退出，不下发游戏奖励");
              _this162.playADCallBack && _this162.playADCallBack(false);
            }
          });
        }
      } else {
        this.playADCallBack && this.playADCallBack(1006);
      }
    }
  }, {
    key: "vibrate",
    value: function vibrate() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
      if (e) {
        window.my.vibrateShort();
      } else {
        window.my.vibrateLong();
      }
    }
  }, {
    key: "share",
    value: function share(e, t) {
      console.log("shareDiyMap:", JSON.stringify(e));
      window.my.onShareAppMessage = function () {
        return {
          title: "小游戏",
          desc: "这个小游戏真好玩",
          success(e) {
            console.log(e);
            t(true);
          },
          fail(e) {
            console.log("fail:" + e);
            t(false);
          },
          complete(e) {
            console.log("complete:" + e);
          }
        };
      };
    }
  }, {
    key: "interstitialShow",
    value: function interstitialShow(e) {
      var _this163 = this;
      if (!this.isAdOk()) {
        return;
      }
      console.log("zfb_interstitialShow", e);
      var t = "";
      t = e ? $2Platformconf.default.Instance.getconfig().ZFBGame.Interstitial[e] : $2Platformconf.default.Instance.getconfig().ZFBGame.Interstitial[0];
      console.log("zfb_interstitialShow:", t);
      this.interstitialAd && this.interstitialAd.destroy();
      console.log("创建插屏:", t);
      this.interstitialAd = window.my.createInterstitialAd({
        adUnitId: t
      });
      this.interstitialAd.onLoad(function () {
        console.log("插屏广告加载成功");
        _this163.interstitialAd.show().then(function () {
          return console.log("interstitialAd 广告显示");
        }).catch(function (e) {
          return console.log("interstitialAd 广告显示错误:" + e);
        });
      });
      this.interstitialAd.onError(function (e) {
        console.log("onError插屏:", e);
      });
      this.interstitialAd.onClose(function (e) {
        e && e.isEnded && console.log("关闭插屏：" + e.isEnded);
      });
    }
  }, {
    key: "bannerDestroy",
    value: function bannerDestroy(e) {
      this.bannerAd.destroy();
    }
  }, {
    key: "bannerCreate",
    value: function bannerCreate(e, t) {
      var _this164 = this;
      if (window.my) {
        this.bannerAd = window.my.createBannerAd({
          adUnitId: this.getbannerid(e),
          style: {
            left: (this.systemInfo.windowWidth - 320) / 2,
            top: this.systemInfo.windowHeight - this.systemInfo.windowHeight / 8,
            width: 320
          }
        });
        this.bannerAd.onLoad(function () {
          console.log("banner 广告加载成功");
          _this164.isShow && _this164.bannerAd.show().then(function () {
            return console.log("banner 广告显示");
          }).catch(function (e) {
            return console.log("banner 广告显示错误:" + e);
          });
        });
        setTimeout(function () {
          _this164.bannerAd && _this164.bannerAd.destroy();
          _this164.bannerCreate(e, t);
        }, 6e4);
      }
    }
  }, {
    key: "bannerShow",
    value: function bannerShow(e, t) {
      this.isShow = true;
      if (this.bannerAd) {
        this.bannerAd.show().then(function () {
          return console.log("banner 广告显示");
        }).catch(function (e) {
          return console.log("banner 广告显示错误:" + e);
        });
      } else {
        this.bannerCreate(e, t);
      }
    }
  }, {
    key: "bannerHide",
    value: function bannerHide(e) {
      this.isShow = false;
      this.bannerAd && this.bannerAd.hide();
    }
  }, {
    key: "getbannerid",
    value: function getbannerid(e) {
      if (e) {
        return $2Platformconf.default.Instance.getconfig().ZFBGame.banner[e];
      } else {
        return $2Platformconf.default.Instance.getconfig().ZFBGame.banner[0];
      }
    }
  }, {
    key: "isAdOk",
    value: function isAdOk() {
      return this.versionList[0] > this.adVersionList[0] || this.versionList[0] == this.adVersionList[0] && (this.versionList[1] > this.adVersionList[1] || this.versionList[1] == this.adVersionList[1] && this.versionList[2] >= this.adVersionList[2]) || (console.log("支付宝版本过低无法播放：" + this.version), false);
    }
  }, {
    key: "gameInfo",
    value: function gameInfo(e) {
      if (this.countLevel < 3) {
        console.log("gameInfo:", e);
        if (!$2GameUser.default.getInstance().getZfbLevelComplete(e)) {
          this.countLevel++, console.log("getZfbLevelComplete:", this.countLevel), $2GameUser.default.getInstance().setZfbLevelComplete(e, true), this.countLevel >= 3 && (console.log("3次完成发送服务器"), cc.sys.localStorage.setItem("zfbDay", new Date().getDate()), window.my.eqSendEvent("report", {
            id: $2GameUser.default.getInstance().id,
            uid: $2GameUser.default.getInstance().openid,
            action_code: "hzzcw_game_pass_level_3"
          }));
        }
      }
    }
  }]);
}($2MiniBase.default);